package com.mf.pte.techique;

import com.mf.pte.pojo.Item;
import com.mf.pte.utils.StringUtil;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
@AllArgsConstructor
public class ProcedurePatcher {

    private List<Procedure> procedures;

    private String totalPurpose;

    public ProcedurePatcher(){
        this.procedures = new ArrayList<>();
    }

    public void print(int level){
        System.out.println(StringUtil.getXTable(level).append(totalPurpose));
        for (Procedure procedure : procedures) {
            procedure.print(level+1);
        }
    }

    public void patch(Item product){
        totalPurpose = "装配产品："+product.getComponent().getName();
        ArrayList<Item> componentAssembly = product.getChildren();
        for (Item item : componentAssembly) {
            if(item.isAsm()) {
                procedures.add(new Procedure().generateComponentAssembly(item));
            }
        }

        procedures.add(new Procedure().generateUnitedAssembly(product));
    }

    public void listProcedures(){
        print(0);
    }
}
